package cc.owoo.godpen.analysis.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 当值为列表时，能够进行的操作
 * Created by nimensei
 * 2022-05-28 上午 01:58
 **/
public final class JsonList extends Json {
    private List<Object> list;// 列表数据

    JsonList(List<Object> list) {
        this.list = list;
    }

    @Override
    public Object getData() {
        return list;
    }

    @Override
    boolean setData(Object data) {
        if (!(data instanceof List<?> list))
            return false;
        this.list = (List<Object>) list;
        return true;
    }

    @Override
    boolean setValue(String key, Object value) {
        return false;
    }

    @Override
    boolean setValue(int index, Object value) {
        if (index < 0 || index >= list.size())
            return false;
        try {
            list.set(index, value);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    Object getValue(String key) {
        return null;
    }

    @Override
    Object getValue(int index) {
        if (index < 0 || index >= list.size())
            return null;
        return list.get(index);
    }


    @Override
    public Object removeValue(String key) {
        return null;
    }

    @Override
    public Object removeValue(int index) {
        return null;
    }

    @Override
    Boolean getBooleanValue() {
        return null;
    }

    @Override
    Number getNumberValue() {
        return null;
    }

    @Override
    CharSequence getCharSequenceValue() {
        return null;
    }

    @Override
    public HashMap<String, Object> getHashMap() {
        return null;
    }

    @Override
    public ArrayList<Object> getArrayList() {
        return new ArrayList<>(list);
    }
}
